package com.ikun.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @ClassName Result
 * @Description: 响应结果类
 * @CreateDate: 2024/4/1 14:46
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;

    private String message;

    private T data;

    public Result<T> success() {
        this.setCode(ResponseCodeAndMessage.SUCCESS_CODE);
        this.setMessage(ResponseCodeAndMessage.DEFAULT_SUCCESS_MESSAGE);
        return this;
    }

    public Result<T> success(T data) {
        this.setCode(ResponseCodeAndMessage.SUCCESS_CODE);
        this.setMessage(message);
        this.setData(data);
        return this;
    }

    public Result<T> success(T data,String message) {
        this.setCode(ResponseCodeAndMessage.SUCCESS_CODE);
        this.setMessage(message);
        this.setData(data);
        return this;
    }

    public Result<T> fail() {
        this.setCode(ResponseCodeAndMessage.FAIL_CODE);
        this.setMessage(ResponseCodeAndMessage.DEFAULT_FAIL_MESSAGE);
        return this;
    }

    public Result<T> fail(String message) {
        this.setCode(ResponseCodeAndMessage.FAIL_CODE);
        this.setMessage(message);
        return this;
    }

    public Result<T> fail(Integer code, String message) {
        this.setCode(code);
        this.setMessage(message);
        return this;
    }

    public Result<T> error() {
        this.setCode(ResponseCodeAndMessage.ERROR_CODE);
        this.setMessage(ResponseCodeAndMessage.DEFAULT_ERROR_MESSAGE);
        return this;
    }

    public Result<T> error(String message) {
        this.setCode(ResponseCodeAndMessage.ERROR_CODE);
        this.setMessage(message);
        return this;
    }

    public Result<T> error(Integer code, String message) {
        this.setCode(code);
        this.setMessage(message);
        return this;
    }

}
